package com.group01.community.service.impl;

import com.group01.community.entity.ZyComment;
import com.group01.community.entity.vo.ZyCommentUserVo;
import com.group01.community.entity.vo.ZyCommentVo;
import com.group01.community.mapper.ZyCommentMapper;
import com.group01.community.service.ZyCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.beans.Transient;
import java.util.List;

/**
 * <p>
 * 评论表 服务实现类
 * </p>
 *
 * @author guoyuan
 * @since 2025-05-01
 */
@Service
public class ZyCommentServiceImpl extends ServiceImpl<ZyCommentMapper, ZyComment> implements ZyCommentService {

    @Autowired(required = false)
    private ZyCommentMapper zyCommentMapper;

    @Override
    public List<ZyCommentVo> getAllCommentByInteractionId(Long interactionId) {
        return zyCommentMapper.getAllCommentByInteractionId(interactionId);
    }

    @Override
    public void deleteByCommentIdAfter(Long zcCommentId) {
        zyCommentMapper.deleteByCommentIdAfter(zcCommentId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String deleteInteractionByInteractionId(Long interactionId) {
        List<ZyCommentVo> list = zyCommentMapper.getAllCommentByInteractionId(interactionId);
        for (ZyCommentVo zyCommentVo : list) {
            zyCommentMapper.deleteByCommentIdAfter(zyCommentVo.getZcCommentId());
        }
        zyCommentMapper.deleteInteractionByInteractionId(interactionId);
        return "ok";
    }

    @Override
    public List<ZyCommentUserVo> getAllCommentAndOwner(Long interactionId) {
        return zyCommentMapper.getAllCommentAndOwner(interactionId);
    }
}
